﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Oliving.FormCommon.OlivingUserControl
{
    public partial class OlivingImgMsgForm : MyOlivingBaseForm
    {
        public OlivingImgMsgForm()
        {
            InitializeComponent();
        }

        int _TextColor = 0;
        public OlivingImgMsgForm(string imgPath, string msg = "操作成功!",int type = 0, int TextColor = 0)
        {
            InitializeComponent();
            //   this.TopMost = true;
            this.label1.Text = msg;
            _TextColor = TextColor;

            if (!string.IsNullOrEmpty(imgPath)) { 
            if (File.Exists(imgPath)) { 
            pictureBox1.BackgroundImage = Image.FromFile(imgPath);
            }
            }
            if (type == 0)
            {
                button1.Visible = false;
            }
            else
            {
                button1.Visible = true;
            }
        }

        private void label1_Click(object sender, EventArgs e)
        {
            if (_TextColor == 1)
            {
                Thread thread = new Thread(() =>
                {
                    label1.Invoke(new EventHandler(delegate
                    {
                        label1.ForeColor = Color.Red;
                    }));
                });
                thread.IsBackground = true;
                thread.Start();
            }
        }

        private void OlivingImgMsgForm_Load(object sender, EventArgs e)
        {

            label1_Click(null, null);
        }

        private void button1_Click(object sender, EventArgs e)
        {

            this.DialogResult = DialogResult.Cancel;
        }

        private void btn_Submit_Click(object sender, EventArgs e)
        {

            this.DialogResult = DialogResult.OK;
            this.Close();
        }
    }
}
